package com.oazon.moco.lan.core.udp;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class LanDiscoveryService extends Service {
	private static String TAG = "LanDiscoveryService";

	private LanDiscoveryServer mServer = new LanDiscoveryServer(getBaseContext());

	@Override
	public IBinder onBind(Intent intent) {
		try {
			mServer.start();
		} catch (Exception e) {
			e.printStackTrace();
			Log.d(TAG, "LanDiscoveryServer start failure");
		}
		return new LanDiscoveryServerServiceBinder();
	}

	public class LanDiscoveryServerServiceBinder extends Binder {

	}
	
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		try {
			mServer.start();
		} catch (Exception e) {
			e.printStackTrace();
			Log.d(TAG, "HttpJsonServerService start failure");
		}
		return super.onStartCommand(intent, flags, startId);
	}
	
	@Override
	public void onDestroy() {
		mServer.stop();
		super.onDestroy();
	}
}
